//
//  DiscoverClassifyCollectionViewCellThird.m
//  XYFMApp
//
//  Created by 岁变 on 16/9/7.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "DiscoverClassifyCollectionViewCellThird.h"
#import "XYMacro.h"

@interface DiscoverClassifyCollectionViewCellThird ()


@end

@implementation DiscoverClassifyCollectionViewCellThird

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        _str = [NSString stringWithFormat:@"%ld", _model.item_views];

        _picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_picImageView];

        _backImageVeiw = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_channel_item"]];
        [self.contentView addSubview:_backImageVeiw];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
       // _titleLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_contentLabel];
        
        _playImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"catinfo_play_cnt"]];
        [self.contentView addSubview:_playImageView];
        
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.text = _str;
        _numberLabel.textColor = [UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _numberLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_numberLabel];
        
        _fromLabel = [[UILabel alloc] init];
        _fromLabel.textColor =[UIColor colorWithRed:0.44 green:0.44 blue:0.48 alpha:1.00];
        _fromLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_fromLabel];
        
        
    }
    return self;
}


- (void)setModel:(ClassifyModelFirstTopItems *)model {
    _model = [[ClassifyModelFirstTopItems alloc] init];
    _model = model;
    
    _contentLabel.text = [NSString stringWithFormat:@"最新节目: %@", model.item_lastmusic];
    
    _titleLabel.text = model.item_name;
    _fromLabel.text = [NSString stringWithFormat:@"by %@", model.item_manager];
    
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:model.item_img] placeholderImage:PLACEHOLDERIMAGE];;

}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    [_backImageVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(5);
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.width.mas_offset(100);
        make.height.mas_offset(30);
    }];
    
    [_playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.height.mas_offset(10);
        make.width.mas_offset(10);
    }];
    
    CGRect newRect = [_str boundingRectWithSize:CGSizeMake(0, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo (self.playImageView.mas_right).with.offset(2);
        make.width.mas_offset(newRect.size.width + 5);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-8);
        make.height.mas_offset(15);
    }];
    
    [_fromLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_numberLabel.mas_right).with.offset(20);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-8);
        make.height.mas_offset(15);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(130);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
        make.height.mas_offset(15);
    }];
    
    
    [_picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.width.mas_offset(85);
    }];

    
    
}

@end
